#include <iostream>
#include <vector>
#include <string>
using namespace std;

class Solution 
{
public:
    int longestOnes(vector<int>& nums, const int k) 
    {
        int ret = 0, n = nums.size(), zero = 0;
        for (int left = 0, right = 0; right < n; right++)
        {
            if (nums[right] == 0) zero++;
            while (zero > k)
                if (nums[left++] == 0) zero--;
            ret = max(ret, right - left + 1);
         }
        return ret;
    }
};

void Test01()
{
    vector<int> nums1 = { 1,1,1,0,0,0,1,1,1,1,0 },
        nums2 = { 0,0,1,1,0,0,1,1,1,0,1,1,0,0,0,1,1,1,1 };

    int k = 2;
    Solution s;
    cout << s.longestOnes(nums1, k) << endl;
    //cout << s.longestOnes(nums2, 3) << endl;

}

int main()
{
    Test01();

	return 0;
}